package com.lebang.configuration.thread;

import com.lebang.component.RedisClient;
import com.lebang.configuration.SpringContextHolder;
import com.lebang.service.TaskRouseDetailService;

import static com.lebang.service.TaskRouseDetailService.ROUSE_QUEUE;

/**
 * @Author: hwq
 * @Date: 2019/7/30 11:12
 * @Version 1.0
 */
public class DownApkThread extends Thread {

    private static TaskRouseDetailService taskRouseDetailService = SpringContextHolder.getBean(TaskRouseDetailService.class);
    private static RedisClient redisClient = SpringContextHolder.getBean(RedisClient.class);

    @Override
    public void run() {
        while (true) {
            try {
                long size = redisClient.llen(ROUSE_QUEUE);
                if (size > 0) {
                    String str=redisClient.rpop(ROUSE_QUEUE);
                    taskRouseDetailService.onMessage(str);
                    Thread.sleep(500);
                } else {
                    Thread.sleep(3000);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
